#include "splineproxy.h"

SplineProxy::SplineProxy()
{

}

SplineProxy::~SplineProxy()
{

}


QVector<double> SplineProxy::Interpol( QVector<double> vx_base,
                                        QVector<double> vy_base,
                                        QVector<double> vx_interp)
{
    Spline * pInter = new Spline();
    size_t n = vx_interp.size();
    QVector<double> vy(n);
    pInter->Init(vx_base,vy_base);
    for (size_t i = 0;i<n; ++i)
    {
        vy[i] = pInter->GetInterPol(vx_interp[i]);
    }

    delete pInter;
    return vy;


}

QVector<QVector<double> > SplineProxy::Interpol(QVector<double> vx_base,
                                                 QVector<QVector<double> > vy_base,
                                                 QVector<double> vx_interp)
{
    Spline * pInter = new Spline();
    size_t n = vx_interp.size();

    size_t m = vy_base.size();
    QVector<QVector<double> > vy(m);
    for (size_t j = 0;j<m;++j)
    {
        pInter->Init(vx_base,vy_base[j]);
        vy[j].resize(n);
        for (size_t i = 0;i<n; ++i)
        {
            vy[j][i] = pInter->GetInterPol(vx_interp[i]);
        }
    }

    delete pInter;
    return vy;
}

QVector<double> SplineProxy::Interpol(QVector<double> vy_base,
                                       QVector<double> vx_interp)
{

    Spline * pInter = new Spline();
    size_t m = vy_base.size();
    QVector<double> vx_base(m);
    for (size_t i =0;i<m;++i)
    {
        vx_base[i] = i;
    }

    size_t n = vx_interp.size();
    QVector<double> vy(n);
    pInter->Init(vx_base,vy_base);
    for (size_t i = 0;i<n; ++i)
    {
        vy[i] = pInter->GetInterPol(vx_interp[i]);
    }
    delete pInter;
    return vy;
}

QVector<QVector<double> > SplineProxy::Interpol(QVector<QVector<double> > vy_base,
                                                 QVector<double> vx_interp)
{
    Spline * pInter = new Spline();
    size_t   mx = vy_base.size();
    QVector<QVector<double>> vy(mx);

    if(vy_base.size() == 0) return vy;

    size_t m = vy_base[0].size();
    QVector<double> vx_base(m);
    for (size_t i =0;i<m;++i)
    {
        vx_base[i] = i;
    }

    size_t n = vx_interp.size();

    for (size_t j = 0;j<mx;++j)
    {
        pInter->Init(vx_base,vy_base[j]);
        vy[j].resize(n);
        for (size_t i = 0;i<n; ++i)
        {
            vy[j][i] = pInter->GetInterPol(vx_interp[i]);
            //TRACE("%f",vy[j][i]);
        }
        //TRACE("\n");
    }
    delete pInter;
    return vy;
}
